package com.ayou.eggguard.farm.mapper;

import com.ayou.eggguard.farm.pojo.Keeper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface KeeperMapper {
    @Select("select * from keeper where username=#{username}")
    Keeper getKeeperByUsername(String username);

    @Insert("insert into keeper(username, password, keeper_name, keeper_age, keeper_gender, phone_number, farm_id) " +
            "values(#{keeper.username},#{keeper.password},#{keeper.keeperName},#{keeper.keeperAge},#{keeper.keeperGender},#{keeper.phoneNumber},#{farmId})")
    void addKeeper(@Param("farmId") int farmId,@Param("keeper") Keeper keeper);


    @Select("select * from keeper where farm_id=" +
            "(select chickenfarm.farm_id from chickenfarm where farm_name=#{farmName});")
    List<Keeper> getKeepersByFarmName(String farmName);

    @Delete("delete from keeper where username=#{username}")
    void deleteKeeperByUsername(String username);

    @Update("update keeper set password=#{password} where username=#{username}")
    void resetKeeperPwd(String username,String password);
}
